<?php
echo CHtml::hiddenField('searched-keyword',$keyword);
?>
<div class="box">
    <h2 class="title"><?php echo Yii::t('site/general','search result'); ?></h2>
    <div style="margin-top: 10px; font-size: 14px;"><?php echo Yii::t('site/general','keyword').' : <b>'.$keyword.'</b>'; ?></div>
</div>

<div class="box">
    <h2 class="title"><?php echo Yii::t('site/general','article search result'); ?></h2>
    <img id="article-search-loader" class="searching-loader" src="/image/orange-loader.gif" />
    <div id="article-search-result" class="search-result-section"></div>
</div>

<div class="box">
    <h2 class="title"><?php echo Yii::t('site/general','product search result'); ?></h2>
    <img id="product-search-loader" class="searching-loader" src="/image/orange-loader.gif" />
    <div id="product-search-result" class="search-result-section"></div>
</div>

<div class="box">
    <h2 class="title"><?php echo Yii::t('site/general','document search result'); ?></h2>
    <img id="document-search-loader" class="searching-loader" src="/image/orange-loader.gif" />
    <div id="document-search-result" class="search-result-section"></div>
</div>

<script type="text/javascript">
function loadResult(type,url)
{
    var locale = '<?php echo Yii::app()->language; ?>';
    if (url=='')
    {
        if (type=='article')
            url = '/site/searchArticle/locale/'+locale;
        else if (type=='product')
            url = '/site/searchProduct/locale/'+locale;
        else if (type=='document')
            url = '/site/searchDocument/locale/'+locale;
        if (url=='') return false;
    }
    var url = baseUrl + url;
    $('#'+type+'-search-result').hide();
    $('#'+type+'-search-loader').show();
    $.ajax({
        'type' : 'POST',
        'url' : url,
        'data' : {
            'keyword' : $('#searched-keyword').val()
        },
        'success' : function(data) {
            $('#'+type+'-search-loader').hide();
            $('#'+type+'-search-result').show().html(data);        
        }    
    });
}

$(document).ready(function(){
    loadResult('article','');
    loadResult('product','');
    loadResult('document','');        
});

$('.search-result-section .pager a').live('click',function(){
    var url = $(this).attr('href');
    var type = $(this).closest('.search-result-section').attr('id').replace('-search-result','');
    loadResult(type,url);
    return false;    
});
</script>